import http from './interface'
import store from '@/store'
//设置请求前拦截器
http.interceptor.request = (config) => {
	console.log("====--++++++--"+store.state.userInfo.token)
	config.header = {
		'token': store.state.userInfo.token,
	}

}
//设置请求结束后拦截器
http.interceptor.response = (response) => {
	console.log("=============--------"+store.state.userInfo.token)
	uni.hideLoading()
	if(response.statusCode === 200){
		if ( response.data.code === 20001 || response.data.code === 20002) {
			//未登录
			uni.showToast({
				title: response.data.message,
				duration: 1200,
				icon: 'none'
			})
		setTimeout(function() {
			uni.reLaunch({
				url: '/pages/mine/author',
				animationType: 'slide-in-bottom',
				"animationDuration": 450
			});
			console.log('拦截拦截拦截')
		}, 450);
			store.commit('logout')
			return
		}
	}else{
		uni.showToast({
			title: '网络好像不太通畅~',
			duration: 1200,
			icon: 'none'
		})
	}

}

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 *
 */

export const gethospitallist = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: 'api/order/get_hospital_list',
		method: 'POST',
		data
	})
}
export const chooseemployee = (data) => {
	return http.request({
		url: 'api/order/choose_employee',
		method: 'POST',
		data
	})
}
export const getserviceobject = (data) => {
	return http.request({
		url: 'api/order/get_service_object',
		method: 'POST',
		data
	})
}
export const addserviceobject = (data) => {
	return http.request({
		url: 'api/order/add_service_object',
		method: 'POST',
		data
	})
}
export const delserviceobject = (data) => {
	return http.request({
		url: 'api/order/remove_binding',
		method: 'POST',
		data
	})
}
export const submitorder = (data) => {
	return http.request({
		url: 'api/order/submit_order',
		method: 'POST',
		data
	})
}
export const Listorder = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: 'api/order/List_order',
		method: 'POST',
		data
	})
}
export const orderInfo = (data) => {
	return http.request({
		url: 'api/order/order_particulars',
		method: 'POST',
		data
	})
}
export const ordercancel = (data) => {
	return http.request({
		url: 'api/order/order_cancel',
		method: 'POST',
		data
	})
}
export const orderevaluate = (data) => {
	return http.request({
		url: 'api/order/order_evaluate',
		method: 'POST',
		data
	})
}
export const refundorderlist = (data) => {
	return http.request({
		url: 'api/order/refund_order_list',
		method: 'POST',
		data
	})
}
export const getUserInfo = (data) => {
	return http.request({
		url: 'api/user/getUserInfo',
		method: 'POST',
		data
	})
}
export const refundlist = (data) => {
	return http.request({
		url: 'api/order/refund_list',
		method: 'POST',
		data
	})
}
export const refunddetails = (data) => {
	return http.request({
		url: 'api/order/refund_details',
		method: 'POST',
		data
	})
}
export const wxpax = (data) => {
	return http.request({
		url: 'api/wx_pay/wx_pax',
		method: 'POST',
		data
	})
}
export const refundmoney = (data) => {
	return http.request({
		url: 'api/order/rule_rule',
		method: 'POST',
		data
	})
}
export default {
	gethospitallist,
	chooseemployee,
	getserviceobject,
	addserviceobject,
	delserviceobject,
	submitorder,
	Listorder,
	orderInfo,
	ordercancel,
	orderevaluate,
	refundorderlist,
	getUserInfo,
	refundlist,
	refunddetails,
	wxpax,
	refundmoney,
}
